package studio.raptor.extractor.segment.holder;

import java.util.HashSet;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import studio.raptor.extractor.segment.server.ExtractorServer;

/**
 * Created by liuyong8 on 2017/8/9.
 */
public class ExtractorServerHolder {

  private static final Logger log = LoggerFactory.getLogger(ExtractorServerHolder.class);

  private static Set<ExtractorServer> servers = new HashSet<>();

  private static Set<ExtractorServer> startedServers = new HashSet<>();

  public static void addServer(ExtractorServer extractorServer) {
    servers.add(extractorServer);
  }

  public static void addStartedServer(ExtractorServer extractorServer) {
    startedServers.add(extractorServer);
  }

  public static void startUp() throws Exception {
    for (ExtractorServer server : servers) {
      server.startup();

    }
  }

  public static void shutDown() {
    for (ExtractorServer server : startedServers) {
      try {
        server.shutDown();
        log.info("server have shutdown success,kindId = {}",server.getServerConfig().getKindId());
      } catch (Exception e) {
        e.printStackTrace();
        log.error("server have shutdown failed,kindId = {}",server.getServerConfig().getKindId());
      }

    }
  }
}
